---
title: "Analysis"
author: "Yiming"
date: "2021/10/26"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```


```{r echo=FALSE, warning = FALSE, message = FALSE, results = "asis"}
# setup
library(stargazer)
library(interactions)
library(ggplot2)
df <- read.csv("data_with_media_measures.csv")

df$trump <- (df$approve_trump + df$favor_trump)/2
df$pre_trump <- (df$pre_approve_trump + df$pre_favor_trump)/2

df$gender <- factor(df$gender, levels = c("Male", "Female"))
df$race <- factor(df$race, levels = c("White", "Black", "Hispanic", "Other"))

df$cg_votecounted <- df$votecounted - df$pre_votecounted
df$cg_trump <- df$trump - df$pre_trump

```

### Table S3. Cross-sectional models of pre-election news use patterns on pre-election beliefs

```{r echo=FALSE, warning = FALSE, message = FALSE, results = "asis"}
# standardization
df$pre_votecounted <- (df$pre_votecounted - mean(df$pre_votecounted, na.rm=TRUE))/sd(df$pre_votecounted, na.rm=TRUE)
df$pre_trump <- (df$pre_trump - mean(df$pre_trump, na.rm=TRUE))/sd(df$pre_trump, na.rm=TRUE)
df$pre_partisan_news_flow <- (df$pre_partisan_news_flow - 
                                mean(df$pre_partisan_news_flow, na.rm=TRUE))/sd(df$pre_partisan_news_flow, na.rm=TRUE)
df$pre_outlet_diversity <- (df$pre_outlet_diversity - 
                              mean(df$pre_outlet_diversity, na.rm=TRUE))/sd(df$pre_outlet_diversity, na.rm=TRUE)
df$pre_far_left <- (df$pre_far_left - mean(df$pre_far_left, na.rm=TRUE))/sd(df$pre_far_left, na.rm=TRUE)
df$pre_far_right <- (df$pre_far_right - mean(df$pre_far_right, na.rm=TRUE))/sd(df$pre_far_right, na.rm=TRUE)
#
df$votecounted <- (df$votecounted - mean(df$votecounted, na.rm=TRUE))/sd(df$votecounted, na.rm=TRUE)
df$trump <- (df$trump - mean(df$trump, na.rm=TRUE))/sd(df$trump, na.rm=TRUE)
df$partisan_news_flow <- (df$partisan_news_flow - 
                                mean(df$partisan_news_flow, na.rm=TRUE))/sd(df$partisan_news_flow, na.rm=TRUE)
df$outlet_diversity <- (df$outlet_diversity - 
                              mean(df$outlet_diversity, na.rm=TRUE))/sd(df$outlet_diversity, na.rm=TRUE)
df$far_left <- (df$far_left - mean(df$far_left, na.rm=TRUE))/sd(df$far_left, na.rm=TRUE)
df$far_right <- (df$far_right - mean(df$far_right, na.rm=TRUE))/sd(df$far_right, na.rm=TRUE)
df$cg_votecounted <- (df$cg_votecounted - mean(df$cg_votecounted, na.rm=TRUE))/sd(df$cg_votecounted, na.rm=TRUE)
df$cg_trump <- (df$cg_trump - mean(df$cg_trump, na.rm=TRUE))/sd(df$cg_trump, na.rm=TRUE)

df$voterfraud <- (df$voterfraud - mean(df$voterfraud, na.rm=TRUE))/sd(df$voterfraud, na.rm=TRUE)


m1 <- lm(pre_votecounted ~ pre_partisan_news_flow + pre_outlet_diversity + pre_far_left + age + gender + race + education + income, data = df)
summary(m1)
m2 <- lm(pre_trump ~ pre_partisan_news_flow + pre_outlet_diversity + pre_far_left + age + gender + race + education + income, data = df)
summary(m2)

stargazer(m1, m2,
          single.row = FALSE,
          type = "html",
          digits = 3,
          no.space = TRUE,
          ci = TRUE,
          star.char = c("*", "**", "***"),
          star.cutoffs = c(0.05, 0.01, 0.001),
          notes = c("* p<0.05; ** p<0.01; *** p<0.001"), 
          notes.append = F)

```

### Table 5. Cross-sectional models of post-election news use patterns and post-election beliefs

```{r echo=FALSE, warning = FALSE, message = FALSE, results = "asis"}

m1 <- lm(votecounted ~ partisan_news_flow + outlet_diversity + far_left + age + gender + race+ education + income, data = df)
summary(m1)

m2 <- lm(trump ~ partisan_news_flow + outlet_diversity + far_left + age + gender + race+ education + income, data = df)
summary(m2)

m3 <- lm(voterfraud ~ partisan_news_flow + outlet_diversity + far_left + age + gender + race+ education + income, data = df)
summary(m3)


stargazer(m1, m2, m3,
          single.row = FALSE,
          type = "html",
          digits = 3,
          no.space = TRUE,
          ci = TRUE,
          star.char = c("*", "**", "***"),
          star.cutoffs = c(0.05, 0.01, 0.001),
          notes = c("* p<0.05; ** p<0.01; *** p<0.001"), 
          notes.append = F)

```



### Table 6. The interaction effects between news use slant and diversity 

```{r echo=FALSE, warning = FALSE, message = FALSE, results = "asis"}

m1 <- lm(votecounted ~ partisan_news_flow*outlet_diversity + far_left + age + gender + race+ education + income, data = df)

m2 <- lm(voterfraud ~ partisan_news_flow*outlet_diversity + far_left + age + gender + race+ education + income, data = df)


stargazer(m1, m2,
          single.row = FALSE,
          type = "html",
          digits = 3,
          no.space = TRUE,
          ci = TRUE,
          star.char = c("*", "**", "***"),
          star.cutoffs = c(0.05, 0.01, 0.001),
          notes = c("* p<0.05; ** p<0.01; *** p<0.001"), 
          notes.append = F)

```

